package org.bigstones.orgnzr.ui.server;

import org.bigstones.orgnzr.model.impl.jpa.PlanDao;
import org.bigstones.orgnzr.ui.client.GreetingService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.bigstones.orgnzr.model.impl.jpa.SetupDao;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService {

//	PlanDao m_planDao = new PlanDao();
	SetupDao m_setupDao = new SetupDao();
	
	public String greetServer(String input) {
//		try{
//		   m_planDao.registerUser();
//		}catch (Throwable t) {
//			t.printStackTrace();
//		}
		
		int count = -1;
//		try{
//		  count = m_planDao.getUsersCount();
//		}catch(Exception e){
//			e.printStackTrace();	
//		}
		
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return "Hello, " + input + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent
				+"<br> Created "+count+" users ";
	}
	
	public Boolean setupTestData(){
		try{
  		  m_setupDao.registerInitialData();
  		  return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
}
